home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdtimprk.zip / PDTIMPRK.ASM < prev    next >
Assembly Source File  |  1987-09-02  |  22KB  |  532 lines

  1.         PAGE    ,132    ;  Corrected version, 9/2/87, DF
  2.         TITLE   PDTIMPRK -- Public domain software by Dick Flanagan
  3. ;----------------------------------------------------------------------------+
  4. ;                                                                            |
  5. ;       Placed in the PUBLIC DOMAIN without warranty, guarantee, or          |
  6. ;       assumption of liability.  All rights under copyright law are         |
  7. ;       unconditionally waived by the author.                                |
  8. ;                                                                            |
  9. ;       Written by Dick Flanagan, Ben Lomond, California, August 1987.       |
  10. ;                                                                            |
  11. ;----------------------------------------------------------------------------+
  12.  
  13. comment *
  14.  
  15. PPPPPP   DDDDDD   TTTTTTT  III  M       M  PPPPPP   RRRRRR   K   K
  16. P     P  D     D     T      I   MM     MM  P     P  R     R  K  K
  17. P     P  D     D     T      I   M M   M M  P     P  R     R  K K
  18. PPPPPP   D     D     T      I   M  M M  M  PPPPPP   RRRRRR   KK
  19. P        D     D     T      I   M   M   M  P        R   R    K K
  20. P        D     D     T      I   M       M  P        R    R   K  K
  21. P        DDDDDD      T     III  M       M  P        R     R  K   K
  22.  
  23. *
  24.  
  25. ;----------------------------------------------------------------------------
  26. ;
  27. ;       The purpose of this program is to automatically park fixed disk
  28. ;       drive heads after a predetermined period of inactivity has passed.
  29. ;       
  30. ;       While there are several other programs available to accomplish
  31. ;       this task, almost all are either copyrighted or have evolved from
  32. ;       copyrighted material.  Some of these programs are in the ignorent
  33. ;       position of ostensibly being both copyrighted and in the public
  34. ;       domain, or with restrictions on their "public domainness."  Until
  35. ;       their authors realize they can't have it both ways, these programs
  36. ;       are assumed to be copyrighted.
  37. ;
  38. ;       Program Syntax:  PDTIMPRK <minutes>
  39. ;
  40. ;       The <minutes> parameter is a single digit in the range of 1 to 9.
  41. ;       It represents the number of minutes of inactivity that are to be
  42. ;       allowed before the heads are to be automatically parked.  Some
  43. ;       people might like a slightly lower floor on this value, but
  44. ;       (and since I can't imagine anyone realistically wanting a higher
  45. ;       ceiling) I have retained this convention which is common in
  46. ;       other programs.
  47. ;
  48. ;       Only BIOS I/O functions are used, so the program should be
  49. ;       usable across a broad spectrum of IBM-compatible computers.
  50. ;
  51. ;       Theory of Operation:
  52. ;
  53. ;       Every time a software interrupt 13 is issued it is inter-
  54. ;       cepted by this program which checks if the request is for
  55. ;       a fixed or floppy disk.  If it is for a fixed disk, a
  56. ;       count-down timer is reset and a flag is cleared to indicate
  57. ;       that the disk heads are probably no longer parked.
  58. ;
  59. ;       Every time a hardware timer interrupt 8 is detected it is
  60. ;       also intercepted and, if the disks are not already parked
  61. ;       and we are not in the process of parking them, the timer is
  62. ;       decremented and checked to see if the interval has expired.
  63. ;       If it has, a flag is set indicating that parking is in pro-
  64. ;       gress, the disks are "seeked" to their innermost cylinder,
  65. ;       the parking-in-progress flag is cleared, the heads-are-parked
  66. ;       flag is set, and our task is done until the next interrupt
  67. ;       13 for one of the fixed disks sets our timer running again.
  68. ;
  69. ;       The hardware timer interrupt 8 is used instead of the more
  70. ;       conservative approach of using the bios-generated software
  71. ;       interrupt 1C.  The length of time required to park the disk
  72. ;       heads requires that at least the timer interrupts be enabled
  73. ;       during the parking, and the parking operation itself requires
  74. ;       that disk interrupts be enabled.  These effectivly dictate
  75. ;       that we operate with all interrupts enabled.
  76. ;
  77. ;       To enable interrupts from within the interrupt 1C logic would
  78. ;       require that an EOI (End-Of-Interrupt) code be sent to the
  79. ;       8259A PIC (Programmable Interrupt Controller).  The problem
  80. ;       with this is that the Time Of Day interrupt handler that issued
  81. ;       the interrupt 1C in the first place will issue another EOI to
  82. ;       the 8259A as soon as we return.  This second EOI can wreak
  83. ;       havok with lower level interrupt handlers that may have been
  84. ;       interrupted by the original timer interrupt.
  85. ;
  86. ;       Instead, we intercept timer interrupt 8 and immediately pass
  87. ;       it off to the bios Time Of Day routine.  When we get control
  88. ;       back, the EOI will already have been issued and we can proceed
  89. ;       with a clear conscience.
  90. ;
  91. ;       Author's Notes:
  92. ;
  93. ;       Because I hate TSR's, I try to make them as small as possible.
  94. ;       This one is about as small as I've seen with equivalent
  95. ;       functionality.
  96. ;
  97. ;       I have attempted to comment the code in such a way that its
  98. ;       operation should be clearly evident and modifications or
  99. ;       (horrors!) bug fixes should be easily implemented.  I also
  100. ;       hope the comments will help remove some of the mystery that
  101. ;       surrounds assembly language in general and interrupt handlers
  102. ;       in particular for many people.
  103. ;
  104. ;       Because this program was a quick weekend project, its level of
  105. ;       parameter checking and error recovery is minimal, but I feel it
  106. ;       to be adequate for the task at hand.  For example:
  107. ;
  108. ;       Limitations:
  109. ;
  110. ;       o  Only the first non-blank, non-zero character on the command
  111. ;          line is examined.  If 20 is entered, the 2 will be accepted
  112. ;          and the 0 will be ignored.
  113. ;
  114. ;       o  If one drive in a two-drive system is kept busy frequently
  115. ;          enough so as not to be parked, the other drive, regardless
  116. ;          of how idle it might be, will not be parked until the other
  117. ;          one finally is (the old two-drive-one-timer problem).
  118. ;
  119. ;       o  No attempt is made to determine if the program has already
  120. ;          been installed.  Simple tests are easily confused and complex
  121. ;          ones aren't worth the trouble for a program as small and
  122. ;          benign as this.
  123. ;
  124. ;       o  No error recovery is attempted.
  125. ;
  126. ;----------------------------------------------------------------------------
  127.  
  128. CODE    SEGMENT PARA
  129.         ASSUME  CS:CODE, DS:NOTHING, ES:NOTHING, SS:NOTHING
  130.  
  131.         ORG     0100H                   ; reserve space for psp
  132. START:  JMP     INIT                    ; jump to initialization code
  133.  
  134. INT08VECT       LABEL   DWORD           ; pre-existing interrupt 08 vector
  135. INT08OFF        DW      0               ;
  136. INT08SEG        DW      0               ;
  137.  
  138. INT13VECT       LABEL   DWORD           ; pre-existing interrupt 13 vector
  139. INT13OFF        DW      0               ;
  140. INT13SEG        DW      0               ;
  141.  
  142. DRV0CYL         DW      0               ; cylinder to park drive 0
  143. DRV1CYL         DW      0               ; cylinder to park drive 1
  144.  
  145. PARKED          DB      0               ; non-zero = drives are parked
  146. BUSY            DB      0               ; non-zero = parking in progress
  147.  
  148. TIMER           DW      0               ; decremented-to-zero timer counter
  149. TICKS           DW      0               ; timer reset value
  150.  
  151. ;----------------------------------------------------------------------------
  152. ;
  153. ;       all disk i/o via interrupt 13 is intercepted here.  while all
  154. ;       int 13 activity does not necessarily result in the disk drives
  155. ;       becoming 'unparked,' the penalty in so assuming is reasonably
  156. ;       small.
  157. ;
  158. ;----------------------------------------------------------------------------
  159.  
  160. INT13   PROC
  161.  
  162. ;
  163. ;       the less time spent with interrupts disabled the better, so
  164. ;       reenable them right away
  165. ;
  166.         STI                             ; enable interrupts
  167.  
  168. ;
  169. ;       c